﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace HandlingProcedures
{
    /// <summary>
    /// Interaction logic for WindoShowProcedures.xaml
    /// </summary>
    public partial class WindowShowProcedures : Window
    {
        public WindowShowProcedures()
        {
            InitializeComponent();
        }

        //Загрузка окна
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ComboBoxProcesures.ItemsSource = App.DataBase.LoadProcedures();
        }

        //Выбор процедуры
        private void ComboBoxProcesures_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (calendar.SelectedDate != null)
            {
                ShowProcedures();
            }
        }

        //Выбор процедурной комнаты
        private void ComboBoxProcRooms_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ComboBoxProcesures.SelectedIndex != -1 && calendar.SelectedDate != null)
            {
                App.DataBase.LoadAssignedRoomsForProcedure(ComboBoxProcesures.SelectedItem.ToString(), (DateTime)calendar.SelectedDate, ComboBoxProcRooms.SelectedItem.ToString());
            }
        }

        //выбор даты
        private void calendar_SelectedDatesChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ComboBoxProcesures.SelectedIndex != -1)
            {
                ShowProcedures();
            }
        }

        private void CloseWindow_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void ShowProcedures()
        {

            dataGridFreeRooms.ItemsSource = App.DataBase.LoadAssignedRoomsForProcedure(ComboBoxProcesures.SelectedItem.ToString(), (DateTime)calendar.SelectedDate, ComboBoxProcRooms.SelectedIndex == -1 ? null : ComboBoxProcRooms.SelectedItem.ToString());
            ComboBoxProcRooms.ItemsSource = App.DataBase.LoadProcRooms(ComboBoxProcesures.SelectedItem.ToString(), (DateTime)calendar.SelectedDate);
            //ComboBoxProcRooms.Items.Add(null);
        }
    }
}
